<?php

namespace Cck\ArticlesSystem\Console;

use Illuminate\Console\Command;

class InstallCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'articles-system:install
                            {--force : 强制安装}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '初始化文章系统';

    /**
     * Execute the console command.
     *
     * @return void
     */
    public function handle()
    {
        $force = $this->option('force');

        if (!$this->checkInstall()) {
            $this->error('文件已存在');
        }

        $this->call('vendor:publish', [
            '--provider' => 'Tymon\JWTAuth\Providers\LaravelServiceProvider'
        ]);

        $this->call('jwt:secret');
    }

    protected function checkInstall()
    {
        $files = [
            config_path('jwt.php')
        ];

        foreach ($files as $file) {
            if (file_exists($file)) {
                return false;
            }
        }

        return true;
    }
}
